home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amoszine 11
/
Amoszine 11 (Disk 2 of 2).adf
/
Ben_Wyatt_Source.lha
/
Add_Extension.AMOS
/
Add_Extension.amosSourceCode
Wrap
AMOS Source Code
|
2004-04-12
|
3KB
|
137 lines
' File Extension Adder
' ~~~~~~~~~~~~~~~~~~~~
' by Ben Wyatt, bwyatt@paston.co.uk
' Adds an extension to a file, if it has an extension or not
' Hope all the text stays on a Ntsc screen ;-)
Screen Open 0,640,256,2,Hires
Screen Display 0,128,37,640,256
Flash Off : Cls 0
Palette $0,$FFF
Locate ,2 : Centre "File Extension Adder"
Locate ,3 : Centre "~~~~~~~~~~~~~~~~~~~~"
Locate ,6 : Centre 'Type in a file, eg "DH0:Data/Picture"'+" (Doesn't have to exist)"
Put Key "DH0:Data/Picture"
Locate 5,7 : Input "Just here=>";F$
Locate ,9 : Centre 'Thats good, now type in an file extension, eg "iff" or "info"'
Put Key "iff"
Locate 3,10 : Input "Type it now=>";X$
' Here it is
' ~~~~~~~~~~
' *****
' *****
' *****
' *****
' ***********
' *********
' *******
' *****
' ***
' *
'
' WWWWWWWWWWWWWWWWWWW
_ADDEXTENSION[F$,X$]
' MMMMMMMMMMMMMMMMMMM
'
' *
' ***
' *****
' *******
' *********
' ***********
' *****
' *****
' *****
' *****
Locate ,12 : Centre "And here they are together"
Locate ,14 : Centre '"'+Param$+'"'
Locate ,16 : Centre "Impressive isn't it?"
Locate ,17 : Centre "Maybe not"
Locate ,19 : Centre "But it does have its uses..."
Locate ,21 : Centre "Press a key"
Wait Key
X$="AxtYpLWqZzz"
F$=Fsel$("","",'Input filename, ensure file ends in ".'+X$+'"',"(See what happens if you don't put it in correctly)")
Locate ,21 : Centre " "
_FILENAME[F$]
Locate 0,21 : Print "Inputted filename:"+Param$
_ADDEXTENSION[F$,X$]
_FILENAME[Param$]
Locate 0,23 : Print "New filename:"+Param$
Locate ,25 : Centre "Press a key"
Wait Key
Edit
Procedure _ADDEXTENSION[F$,X$]
' Adds file extension X$ to F$, eg F$="Data", X$="s", Param$="Data.s"
' Detects if it's already been added, and puts it in the case of X$...
' eg F$="Screen.iff" changes to "Screen.IFF" if X$="IFF"
' Remove all the comments to make it easier to follow :-)
' Get rid of the pathname and gets the filename on its own
_FILENAME[F$] : FILENAM$=Param$
' Get rid of the "." in X$ if the user has put one in
X$=X$-"."
' Check for the X$ bit and add it if nessassary
XPOS=Instr(FILENAM$,"."+X$)
' If position of extension is not at the end, ie not at all / in the middle
If XPOS<>Len(FILENAM$)-1-Len(X$)
' If X$ isn't in F$ at all then...
If XPOS=0 : XPOS=Instr(FILENAM$,".")
If XPOS=0
' If there's no "." then just add X$ to F$
F$=F$+"."+X$
Else
' If there's a "." somewhere, put it after that
F$=Left$(F$,XPOS+(Len(F$)-Len(FILENAM$)))+X$
End If
Else
' Let F$=F$ upto where X$ is included and put it in the case of X$
F$=Left$(F$,XPOS+1)+X$
End If
Else
' Put it in the case of X$
F$=Left$(F$,Len(F$)-Len(X$))+X$
End If
End Proc[F$]
Procedure _BWINSTR[A$,C$]
' Backwards Instr command/procedure
' A$=Input string, C$=Search string
X=Len(A$)
While Mid$(A$,X,1)<>C$ and X>0
Dec X
Wend
End Proc[X]
Procedure _FILENAME[F$]
' Get filename from pathname and filename F$
' eg. "DH0:Data/Pic.iff" would return "Pic.iff"
' Get positions of "/" and ":"
_BWINSTR[F$,"/"] : SLASH=Param : _BWINSTR[F$,":"] : CLON=Param
' Chop out filename
F$=Right$(F$,Len(F$)-Max(SLASH,CLON))
End Proc[F$]